#include <iostream>

using namespace std;
int n;
const int N = 100010;
int a[N];
int main(){
    cin >> n;
    int mc = 1;
    for(int i = 0; i < n; i ++)
    scanf("%d", &a[i]);
    for(int i =0; i < n; i++)
    {
        if(a[i] == 0) a[i] = mc;
        if(a[i]>mc) mc = a[i];

    }

    for(int i = 0; i < n; i++)
        printf("%d ", a[i]);
    return 0;

}